<template>
	<view>
		<view class="content">
			<view class="header">
				<view class=""><text>收银员</text></view>
				<button class="btn" @click="add">添加</button>
				<button class="btn" @click="del">删除</button>
			</view>
			<radio-group >
				<block v-for="(item,index) in mchList" :key="index">
					<view class="body">
						<view class="radio">
							<radio @click="radioChange(item.cashier_id)"></radio>
						</view>
						<view class="bodyInner">
							<view class="">收银员 ：{{item.nickname}}</view>
						</view>
						<view class="bodyInner">
							<view class="">{{item.phone}}</view>
						</view>
					</view>
				</block>
			</radio-group>
		</view>
	</view>
</template>

<script>
	import eonfox from '@/components/eonfox/eonfox.js';
	import fns from '@/components/eonfox/fns.js';
	var ef=new eonfox();
	export default{
		data(){
			return{
				mchId:'',
				mchList:'',
				cashier_id:''
			}
		},
		onShow(){
			var _this=this;
			ef.submit({
				request:{mch:['MERCHANTSELF']},
				callback(data){
					var re=fns.checkError(data,['mch'],function(errno,error){
						uni.showToast({
							title:error,
							icon:'none'
						})
					})
					console.log(re)
					if(re.mch[0]){
						_this.mchId=re.mch[0].id
					}
					_this.load()
				}
			})
		},
		methods:{
			radioChange(e){
				console.log(e)
				this.cashier_id=e
			},
			load(){
				var _this=this;
				ef.submit({
					request:{mch:['MERCHANTCASHIERSELFLIST',[{merchant_id:_this.mchId}]]},
					callback(data){
						var re=fns.checkError(data,['mch'],function(errno,error){
							uni.showToast({
								title:error,
								icon:'none'
							})
						})
						console.log(re)
						if(re.mch && re.mch.data){
							_this.mchList=re.mch.data
						}
					}
				})
			},
			add(){
				uni.navigateTo({
					url:'../cashier/addCashier'
				})
			},
			del(){
				var _this=this;
				if(_this.cashier_id){
				ef.submit({
					request:{s:['MERCHANTCASHIERSELFREMOVE',[{cashier_id:_this.cashier_id}]]},
					callback(data){
						var re=fns.checkError(data,['s'],function(errno,error){
							uni.showToast({
								title:error,
								icon:'none'
							})
						})
						console.log(re)
						if(re.s){
							uni.showToast({
								title:'删除成功',
								success() {
									_this.load();
								}
							})
						}
					  }
				   })
				}else{
					uni.showToast({
						title:'请选择要删除的收银员',
						icon:'none'
					})
				}
			}
		}
	}
</script>

<style>
	page{
		background-color: #f9f9f914;
	}
	.content{
		display: flex;
		flex-direction: column;
		flex: 1;
		margin: 10px;
		color: #333333;
	}
	.header{
		display: flex;
		flex-direction: row;
		flex: 1;
		height: 120upx;
		font-size: 15px;
		line-height:  120upx;
	}
	.header>view{
		flex: 1;
		justify-content: space-between;
	}
	.body{
		display: flex;
		flex-direction: row;
		flex: 1;
		margin: 5px 0;
		font-size: 14px;
		height:100upx;
		border: #c9cfd0 solid 1px;
		border-radius: 5px;
		background-color: #efefef;
	}
	.radio{
		width: 10%;
	}
	.radio radio{
		margin-top: 20upx;
		margin-left: 10upx;
	}
	.bodyInner{
		display: flex;
		flex-direction: column;
		flex: 1;
		padding: 8px 3px;
		justify-content:space-between;
		margin: 5px;
	}
	.btn{
		width: 160upx;
		height: 60upx;
		background-color: #05a3b7;
		color: #FFFFFF;
		font-size: 28upx;
		line-height: 60upx;
		margin-top: 30upx;
		margin-left: 40upx;
	}
</style>
